package com.hyfrogx.modules.manage.controller.imitation;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyfrogx.common.qcloud.UploadUtils;
import com.hyfrogx.common.utils.Query;
import com.hyfrogx.common.utils.QueryExt;
import com.hyfrogx.common.utils.R;
import com.hyfrogx.modules.manage.entity.imitation.ImitationEntity;
import com.hyfrogx.modules.manage.form.imitation.addImitationForm;
import com.hyfrogx.modules.manage.service.imitation.ImitationService;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Author: Luo
 * @Date: 2019/12/17 13:40
 */
@RestController
@RequestMapping("imitation")
public class ImitationController {

    @Resource
    ImitationService imitationService;

    /**
     * 上传COS
     * @param file
     * @return
     */
    @ApiOperation("COS上传")
    @PostMapping("/upload")
    public R upload(@RequestParam("file") MultipartFile file) {
        // 文件路径
        String url = "";
        // 腾讯云
        url = UploadUtils.uploadWebFile(file, "/imitation");
        return R.ok().put("filename",url);
    }

    @GetMapping("getList")
    public R getList(@RequestParam Map map){
        Page page = imitationService.getList(new QueryExt(map));
        return R.ok().put("data",page);
    }

    @GetMapping("getInfoById")
    public R getInfoById(@RequestParam Integer id){
        Map map = imitationService.getInfo(id);
        return R.ok().put("data",map);
    }

    @PostMapping("add")
    public R add(@RequestBody @Validated addImitationForm form){
        Boolean save = imitationService.save(form);
        if(save){
            return R.ok();
        }else {
            return R.error();
        }
    }


}
